<?php

class M_invoice extends CI_Model
{
    public function invoice_phan_trang_all($limit,$start)
        {
            $this->db->limit($limit);
            $this->db->offset($start);
            $this->db->order_by('INVOICE_ID desc');
            $result= $this->db->get('invoice');
            if($result->num_rows()>0)
                return $result->result();
            else
                return false;
        }
         public function count_data_all()
        {
            return $this->db->count_all('invoice');
        }
        public function invoice_khong_phan_trang_chua_xu_ly()
        {
            $this->db->where(array('INVOICE_STATUS !='=>'12'));
            $this->db->order_by('INVOICE_ID desc');
            $result= $this->db->get('invoice');
            if($result->num_rows()>0)
                return $result->result();
            else
                return false;
        }
         public function invoice_phan_trang_chua_xu_ly($limit,$start)
        {
            $this->db->limit($limit);
            $this->db->offset($start);
            $this->db->where(array('INVOICE_STATUS !='=>'12'));
            $this->db->order_by('INVOICE_ID desc');
            $result= $this->db->get('invoice');
            if($result->num_rows()>0)
                return $result->result();
            else
                return false;
        }
         public function count_data_chua_xu_ly()
        {
           /* $this->db->limit($limit);
            $this->db->offset($start);*/
            $this->db->where(array('INVOICE_STATUS !='=>'12'));
            $this->db->order_by('INVOICE_ID desc');
            $result= $this->db->get('invoice');
            if($result->num_rows()>0)
                return $result->num_rows();
            else
                return false;
        }
         public function invoice_phan_trang_da_xu_ly($limit,$start)
        {
            $this->db->limit($limit);
            $this->db->offset($start);
            $this->db->where(array('INVOICE_STATUS'=>'12'));
            $this->db->order_by('INVOICE_ID desc');
            $result= $this->db->get('invoice');
            if($result->num_rows()>0)
                return $result->result();
            else
                return false;
        }
        public function count_data_da_xu_ly()
        {
          /*  $this->db->limit($limit);
            $this->db->offset($start);*/
              $this->db->where(array('INVOICE_STATUS'=>'12'));
            $this->db->order_by('INVOICE_ID desc');
            $result= $this->db->get('invoice');
            if($result->num_rows()>0)
                $result->num_rows();
            else
                return false;
        }
        function load_invoice_detail_by_invoice_id($id)
    {
    	$this->db->where('INVOICE_ID', $id);
    	$this->db->join('item','item.ITEM_ID=invoice_detail.ITEM_ID');
    	$result = $this->db->get('invoice_detail');
    	if($result->num_rows()>0)
    		return $result->result();
    	else
    		return false;
    }
    function load_list_invoice_by_accountid($id)
    {
    	$this->db->where('ACCOUNT_ID', $id);
    	$this->db->where('INVOICE_STATUS',2);
    	$result = $this->db->get('invoice');
    	if($result->num_rows()>0)
    		return $result->result();
    	else
    		return false;
    }
    function get_invoice_by_id($id)
    {
        	$this->db->where('INVOICE_ID', $id);
         $result= $this->db->get('invoice');
            if($result->num_rows()>0)
                return $result->result();
            else
                return false;
    }
    function update_don_hang($id,$END_DATE,$INVOICE_STATUS,$APPROVAL_PERSON,$PAYMENT_DESCRIPTION)
    {
        $data['END_DATE'] = $END_DATE;
        $data['INVOICE_STATUS'] = $INVOICE_STATUS;
        $data['APPROVAL_PERSON'] = $APPROVAL_PERSON;
        $data['PAYMENT_DESCRIPTION'] = $PAYMENT_DESCRIPTION;
        return $this->db->update('invoice',$data,array('INVOICE_ID'=>$id));
    }
    function update_don_hang_status($id,$END_DATE,$INVOICE_STATUS,$PAYMENT_DESCRIPTION)
    {
        $data['END_DATE'] = $END_DATE;
        $data['INVOICE_STATUS'] = $INVOICE_STATUS;
        $data['PAYMENT_DESCRIPTION'] = $PAYMENT_DESCRIPTION;
        return $this->db->update('invoice',$data,array('INVOICE_ID'=>$id));
    }
       
} ?>